package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.BindingElderDto;
import com.zzyl.nursing.dto.ByDayDto;
import com.zzyl.nursing.dto.DevicePropertyDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.FelderVo;
import com.zzyl.nursing.vo.ListFamilyVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody BindingElderDto dto,HttpServletRequest request){
        return success(familyMemberService.add(dto,request));
    }

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R<List<FelderVo>> my(HttpServletRequest request){
        return R.ok(familyMemberService.getMy(request));
    }

    @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人")
    public R<List<ListFamilyVo>> listByPage(Integer pageNum, Integer pageSize,HttpServletRequest request){
        return R.ok(familyMemberService.listByPage(pageNum,pageSize,request));
    }



   @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody DevicePropertyDto dto,HttpServletRequest request){
       AjaxResult ajaxResult = familyMemberElderService.queryDevicePropertyStatus(dto, request);
        return ajaxResult;
    }



    @GetMapping("queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(String functionId,Long startTime,Long endTime,String iotId){
        ByDayDto dto = new ByDayDto();
        dto.setFunctionId(functionId);
        dto.setStartTime(startTime);
        dto.setEndTime(endTime);
        dto.setIotId(iotId);
        AjaxResult ajaxResult = familyMemberElderService.queryDeviceDataListByDay(dto);
        return ajaxResult;
    }
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(String functionId,Long startTime,Long endTime,String iotId){
        ByDayDto dto = new ByDayDto();
        dto.setFunctionId(functionId);
        dto.setStartTime(startTime);
        dto.setEndTime(endTime);
        dto.setIotId(iotId);
        AjaxResult ajaxResult = familyMemberElderService.queryDeviceDataListByWeek(dto);
        return ajaxResult;
    }

}
